package view;

import java.awt.Graphics2D;
import java.awt.Window;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import controller.IGameContext;
import controller.IGameController;

public class FullScreen extends Core {
	/* Reference to game board for drawing */
	IGameContext gameContext;
	/* Controller to communicate with */
	IGameController gameController;
	
	/** Constructs a new full screen window */
	public FullScreen(IGameController gameController) {
		this.gameController = gameController;
		init();
	}
	
	/** Initializes the different window components */
	public void init() {
		super.init();
		
		// Set default piece dimensions
		this.setDefaultPieceDimensions();
		
		// Set context
		this.gameContext = this.gameController.getContext();
		
		// Add event listeners
		Window window = this.screen.getFullScreenWindow();
		window.addMouseListener(new MouseClickListener());
		window.addKeyListener(new KeyPressListener());
	}
	
	/** Updates the different game components */
	public void update(double delta) {
		// TODO update game board
	}
	
	/** Draws the different game components */
	public void draw(Graphics2D g) {
		this.gameContext.draw(g);
	}
	
	/* Handles keyboard input */
	private void keyPressHandler(KeyEvent e) {	
		// TODO run correct handler
//		switch (e.getKeyCode()) {
//			case KeyEvent.VK_ESCAPE:
//				this.stop();
//				break;
//			case KeyEvent.VK_U:
//				this.gameBoard.undo();
//				break;
//			case KeyEvent.VK_I:
//				Piece.setRenderImages(true);
//				break;
//			case KeyEvent.VK_O:
//				Piece.setRenderImages(false);
//				break;
//			default:
//				break;
//		}
	}
	
	/* Handles mouse input */
	private void mouseClickedHandler(MouseEvent e) {
		// TODO run correct handler
	}

	/* Adjusts piece size to window size */
	private void setDefaultPieceDimensions() {
		// TODO run correct handler
	}
	
	/** Mouse click event listener */
	private class MouseClickListener extends MouseAdapter {
		public void mouseReleased(MouseEvent e) {
			mouseClickedHandler(e);
		}
	}
	
	/** Key type event listener */
	private class KeyPressListener extends KeyAdapter {
		public void keyPressed(KeyEvent e) {
			keyPressHandler(e);
		}
	}
}